const CracoLessPlugin = require('craco-less');
const TerserPlugin = require('terser-webpack-plugin');
const path = require('path');
const pathResolve = (pathUrl) => path.join(__dirname, pathUrl);
const { name } = require('./package');

module.exports = {
  plugins: [
    {
      plugin: CracoLessPlugin,
      options: {
        lessLoaderOptions: {
          lessOptions: {
            modifyVars: { '@primary-color': '#0075ff' },
            javascriptEnabled: true,
          },
        },
      },
    },
  ],
  webpack: {
    alias: {
      '@': pathResolve('src'),
    },
    plugins: [
      new TerserPlugin({
        // sourceMap: true, // Must be set to true if using source-maps in production
        terserOptions: {
          ecma: undefined,
          warnings: false,
          parse: {},
          compress: {
            drop_console: process.env.NODE_ENV === 'production', // 生产环境下移除控制台所有的内容
            drop_debugger: false, // 移除断点
            pure_funcs: process.env.NODE_ENV === 'production' ? ['console.log'] : '', // 生产环境下移除console
          },
        },
      }),
    ],
    configure: (config) => {
      config.output.library = `${name}-[name]`;
      config.output.libraryTarget = 'umd';
      config.output.chunkLoadingGlobal = `webpackJsonp_${name}`; // 此应用自己的端口号
      return config;
    },
  },
  headers: {
    'Access-Control-Allow-Origin': '*',
  },
  devServer: {
    port: 3001,
  },
};
